import api from '@/http/api'

// 回车搜索方法
export function returnSearchMethod(methodName) {
     // 回车搜索
     document.onkeypress = function(e) {
         var keycode = document.all ? event.keyCode : e.which;
         if (keycode == 13) {
             methodName();// 方法名
             return false;
         }
     };
}

// 获取当前日期
export function setupNowDate() { 
    let nowDate = new Date();
    let date = {
        year: nowDate.getFullYear(),
        month: nowDate.getMonth() + 1,
        date: nowDate.getDate(),
    }
    date.month = date.month < 10 ? "0" + date.month : date.month;
    date.date = date.date < 10 ? "0" + date.date : date.date;
    console.log('ssssssssssssssss'+date);
    let systemDate = date.year + '-' + date.month + '-' + date.date;
    return systemDate;
}

// 获取1个月前日期
export function setupAMonthAgoDate() { 
    let nowDate = new Date();
    let date = {
        year: nowDate.getFullYear(),
        month: nowDate.getMonth(),
        date: nowDate.getDate(),
    }
    date.month = date.month < 10 ? "0" + date.month : date.month;
    date.date = date.date < 10 ? "0" + date.date : date.date;
    console.log('ssssssssssssssss'+date);
    let systemDate = date.year + '-' + date.month + '-' + date.date;
    return systemDate;
}

// 获取1个月内日期数组
export function aMonthDateArray(startTime,endTime) { 
    var lastMonth = [];
    let daysInMonth = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    let nowDate = new Date();
    let mouth = endTime.getMonth();
    for(var i = 0;i<daysInMonth[mouth];i++){
        lastMonth.unshift(startTime(startTime().setDate(startTimee().getDate()-i)).toLocaleDateString())
    }
    return lastMonth
}
// 获取当前日期+时间
export function getCurrentTime() {
    let yy = new Date().getFullYear();
    let mm = new Date().getMonth()+1;
    let dd = new Date().getDate();
    let hh = new Date().getHours();
    let mf = new Date().getMinutes()<10 ? '0'+new Date().getMinutes() : new Date().getMinutes();
    let ss = new Date().getSeconds()<10 ? '0'+new Date().getSeconds() : new Date().getSeconds();
    let gettime = yy+'-'+mm+'-'+dd+' '+hh+':'+mf+':'+ss;
    console.log(gettime)
    return gettime
}

// 判断字符串是否在数组arr中，true=是
export function isArrContainStr(array, str) {
    var index = array.indexOf(str) 
    if(index == -1) {
        return false
    } else {
        return true
    }
    // return index  // -1 说明array中不存在id为str的对象
}